package rush.rushcampus.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import rush.rushcampus.common.Result;
import rush.rushcampus.vo.ArticleVo;
import rush.rushcampus.entity.Article;
import rush.rushcampus.service.IArticleService;
import rush.rushcampus.service.IArticleTagService;
import rush.rushcampus.dto.ArticleDto;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author rush
 * @since 2024-06-11
 */
@RestController
@RequestMapping("/article")
@Api(tags = "文章管理")
public class ArticleController {
    @Autowired
    private IArticleService articleService;
    @Autowired
    private IArticleTagService articleTagService;
    //文章分页查询
    @ApiOperation(value = "文章分页查询")
    @GetMapping("/list")
    //默认值为page = 1,pageSize = 10,title = null
    public Result pageList(@RequestParam(defaultValue = "1") int page ,@RequestParam(defaultValue = "10")int pageSize ,String title , Integer status) {
        String star = null;
        return Result.success(articleService.pageList(page,pageSize,title , status , star));

    }
    //添加文章
    @ApiOperation(value = "添加文章")
    @PostMapping("/add")
    public Result addArticle(@RequestBody ArticleDto ArticleDto) {
        articleService.addArticle(ArticleDto);
        return Result.success("添加成功");
    }
    //删除文章
    @Transactional
    @ApiOperation(value = "删除文章")
    @DeleteMapping("/delete")
    public Result deleteArticle(@RequestParam Long id , Integer commentType) {
        articleService.removeArticle(id ,commentType);

        return Result.success("删除成功");
    }
    //修改文章
    @ApiOperation(value = "修改文章")
    @PostMapping("/update")
    public Result updateArticle(@RequestBody ArticleDto ArticleDto) {
        return articleService.updateArticle(ArticleDto);
    }
    @ApiOperation(value = "根据id查询文章")
    @GetMapping("/getArticleById")
    public Result getArticleById(@RequestParam Long id) {
        return Result.success(articleService.getArticleById(id));
    }

}
